import {getCurrencyTypes} from "@/api/pointsMall";
import {ICurrencyItem} from "@/api/modules/pointsMall";

export function useGetCurrencyType() {
  const currencyTypes = ref<ICurrencyItem[]>([])

  const _getCurrencyTypes = async () => {
    const rs = await getCurrencyTypes()

    currencyTypes.value = rs.payload ?? []
  }

  const getCurrencyLabel = (id: number) => {
    return currencyTypes.value.find(item => item.id === id)?.name ?? ''
  }

  onMounted(() => {
    _getCurrencyTypes()
  })

  return {
    currencyTypes,
    getCurrencyTypes: _getCurrencyTypes,
    getCurrencyLabel
  }
}
